package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.generator.PulseGenerator;
import com.miyake.dsp.generator.PulseSetting;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;

@LabUiAnnotation(caption="Pulse Generator")
public class PulseGeneratorWrapper extends Calculator {
	public static final String OUTPUT_X = "Out-X";
	public static final String OUTPUT_Y = "Out-Y";
	private PulseGenerator processor;
	private PulseSetting setting;
	
	public PulseGeneratorWrapper(PulseSetting setting) {
		this.setting = setting;
		processor = new PulseGenerator(setting);
		initOutput(OUTPUT_X);
		initOutput(OUTPUT_Y);
	}
	@Override
	public synchronized void process() {
		double[] y = processor.getProcessed().getRealPart();
		setOutput(OUTPUT_Y, y);
		double[] x = new double[y.length];
		double step = 1.0 / setting.getFrequency();
		for (int i = 0; i < y.length; i++) {
			x[i] = i * step;
		}
		setOutput(OUTPUT_X, x);
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
